import { useEffect, useState } from "react";

function isFalsy(value: unknown) {
  return value === 0 ? true : !!value;
}
export const parseUrlSting = (params: object) => {
  const obj: object = {};
  Object.keys(params).forEach((key) => {
    // @ts-ignore
    if (isFalsy(params[key])) {
      // @ts-ignore
      obj[key] = params[key];
    }
  });
  return obj;
};
export const useMount = (callback: () => void) => {
  useEffect(() => {
    callback();
  }, []);
};
export const useDebounce = <T>(value: T, delay?: number) => {
  const [debounceValue, setDebounceValue] = useState(value);
  useEffect(() => {
    const timeId = setTimeout(() => {
      setDebounceValue(value);
    }, delay);
    return () => clearTimeout(timeId);
  }, [value, delay]);
  return debounceValue;
};
